package com.zhiyou100.review.day003.demo;

/**
 * @packageName: Test2
 * @className: com.zhiyou100.review.day003.demo
 * @Description: TODO 作业
 * @author: yang
 * @date: 2020/6/3
 */
public   class Test2 {
    public static void main(String[] args) {
//        theMoneyTheChicken();

//        printTheMultiplicationTable();

        System.out.println(judgmentDay());
    }


    /**
     * @Description: TODO 百钱百鸡
     * @name: theMoneyTheChicken
     * @param: []
     * @return: int
     * @date: 2020/6/3 11:52 上午
     * @auther: yang
     */

    public static void theMoneyTheChicken() {
        /*
         *一百文💰，要买100只🐔
         * 🐓：3文
         * 母鸡：2文
         * 🐤：1/3 文
         *
         * 🐓+母鸡+🐤==100 && 🐓*3+母鸡*2+小鸡*(1/3)==100
         *
         * 0~33
         * 0~50
         * 100-rooster-hen
         */
        int rooster;
        int hen;
        int chicken;
        for (rooster = 0; rooster <= 33; rooster++) {
            for (hen = 0; hen <= 50; hen++) {
                for (chicken = 0; chicken <= (100 - rooster - hen); chicken++) {
                    boolean flag = (rooster + hen + chicken == 100 && rooster * 3 + hen * 2 + chicken / 3 == 100 && chicken % 3 == 0);
                    if (flag) {
                        System.out.println("🐓: " + rooster + "  🐔:" + hen + "  🐤:" + chicken);
                    }
                }
            }
        }
    }

    /**
     * @Description: TODO  打印九九乘法表
     * @name: printTheMultiplicationTable
     * @param: []
     * @return: void
     * @date: 2020/6/3 12:40 下午
     * @auther: yang
     */

    public static void printTheMultiplicationTable() {
        System.out.println();
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" " + i + "*" + j + "=" + (i * j) + "\t");
                /*
                 * \t \n 都是制表符
                 */
            }
            System.out.println();
        }

        System.out.println();


        System.out.println();

        for (int i = 9; i > 0; i--) {
            for (int j = i; j > 0; j--) {
                System.out.print(" " + i + "*" + j + "=" + (i * j) + "\t");
                /*
                 * \t \n 都是制表符
                 */
            }
            System.out.println();
        }

        System.out.println();


        for (int i = 1; i < 10; i++) {
            for (int k = 1; k < (10 - i); k++) {
                System.out.print("\t" + "\t");
            }
            for (int j = i; j > 0; j--) {
                System.out.print("\t" + i + "*" + j + "=" + (i * j));
            }
            System.out.println();
        }
        System.out.println();

        for (int i = 1; i < 10; i++) {

            for (int k = 1; k < i; k++) {
                System.out.print("\t" + "\t");
            }

            for (int j = i; j < 10; j++) {
                System.out.print("\t" + i + "*" + j + "=" + (i * j));
            }
            System.out.println();
        }
    }

    public static int judgmentDay() {
        int startYear = 2010;
        int startMonth = 1;
        int startDay = 1;

        int endYear = 2020;
        int endMonth = 6;
        int endDay = 3;
        // 定义变量记录 开始时间和结束时间
        int cntDay = 0;
        // 记录总天数
        for (; startYear < endYear; startYear++) {
            // 计算 从 2010-1-1 到 2019-12-12 的天数
            int maxMonth = 12;
            for (int i = startMonth; i <= maxMonth; i++) {
                cntDay += judgmentDay(startYear, i);
            }
        }
        for (int i = 1; i < endMonth; i++) {
            // 计算 2020-1-1 到 2020-5-31 的天数
            cntDay += judgmentDay(endYear, i);
        }
        return cntDay + endDay - 1;
        // 因为从1月1日开始，所以-1
    }

    /**
     * @Description: TODO  根据年和月份获取本月的天数
     * @name: judgmentDay
     * @param: [year, month]
     * @return: int
     * @date: 2020/6/2 3:50 下午
     * @auther: yang
     */
    public static int judgmentDay(int year, int month) {
        int day = 0;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                day = 31;
                break;
            case 2:
                if (toDetermineLeapYear(year)) {
                    day = 29;
                } else {
                    day = 28;
                }
                break;
            default:
                day = 30;
        }
        return day;
    }

    /**
     * @Description: TODO 判断是不是闰年
     * @name: toDetermineLeapYear
     * @param: [year]
     * @return: void
     * @date: 2020/6/2 3:41 下午
     * @auther: yang
     */
    public static boolean toDetermineLeapYear(int year) {
        //公元年分除以4可整除但除以100不可整除，为闰年。 公元年分除以400可整除，为闰年。
        // 返回true是闰年，false是平年
        return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
    }

}
